package com.jiankang.askhealth.util;

import com.jiankang.askhealth.core.api.base.ApiBaseResultBean;
import com.jiankang.askhealth.core.api.base.ApiThreadContext;

public class ApiThreadLocal {
    private static ThreadLocal<ApiThreadContext> local = new ThreadLocal<ApiThreadContext>();

    public static void set(ApiThreadContext context) {
        local.set(context);
    }

    public static void unset() {
        local.remove();
    }

    public static ApiThreadContext get() {
        ApiThreadContext context = local.get();
        if (context == null) {
            context = new ApiThreadContext();
        }
        return context;
    }


    public static boolean isInternal() {
        boolean internal = false;
        ApiThreadContext context = local.get();
        if (context != null) {
            internal = context.isInternal();
        }
        return internal;
    }

    public static void setInternal(boolean internal) {
        ApiThreadContext context = ApiThreadLocal.get();
        context.setInternal(internal);
        local.set(context);
    }

    public static ApiBaseResultBean getResultData() {
    	ApiBaseResultBean data = null;
        ApiThreadContext context = local.get();
        if (context != null) {
            data = context.getData();
        }
        return data;
    }

    public static void setResultData(ApiBaseResultBean data) {
        ApiThreadContext context = ApiThreadLocal.get();
        context.setData(data);
        local.set(context);
    }

    public static String getJsonpCallback() {
        String jsonpCallback = null;
        ApiThreadContext context = local.get();
        if (context != null) {
            jsonpCallback = context.getJsonpCallback();
        }
        return jsonpCallback;
    }

    public static void setJsonpCallback(String jsonpCallback) {
        ApiThreadContext context = ApiThreadLocal.get();
        context.setJsonpCallback(jsonpCallback);
        local.set(context);
    }

}
